<template>
	<!-- 联系人表单 -->
	<div>
		<FormPanel
			ref="FormPanel"
			:list="initForm"
			:cols="3"
			:formType="'add'"
			:labelWidth="'5em'"
			:isSubmitBtn="false"
			@formChange="formChangeHandle"
			class="mtop"
		/>
		<div class="dialogBottmView">
			<el-button @click="closeDialog">关 闭</el-button>
			<el-button @click="saveDialog(-1)" :loading="saveDialogLoding" type="primary">确定</el-button>
		</div>
	</div>
</template>
<script>
	import { dictionary } from '@/utils/dictMixin';
	export default {
		mixins: [dictionary],
		props:{
			contactData:{
				type:Object,
				required:true,
				default: () => ({})
			}
		},
		data() {
			return {
				initForm: this.initFormFun(),
				saveDialogLoding:false
			};
		},
		mounted(){
			if(this.contactData.type === 'edit'){
				this.initForm.forEach(x => {
					x.initialValue = this.contactData.row[x.fieldName];
				});
			}
		},
		methods: {
			//初始化数据
			// init() {
			//	 this.initForm.forEach(x => {
			//		 x.initialValue = this.pdata.allForm[x.fieldName];
			//	 });
			// },
			formChangeHandle(val) {
				this.saveDialogLoding = true;
				// this.pdata.allForm = Object.assign(this.pdata.allForm,val);
				//传递数据到父组件里
				// this.$emit('click', this.pdata);
				//触发外部的事件，以标志着本表单已经准备完毕
				if(this.contactData.type === 'edit'){
					this.$emit('editClose', {data:val,rowNo:this.contactData.rowNo});
				}else{
					this.$emit('saveClose', val);
				}
			},
			saveDialog(){
				this.$refs.FormPanel.SUBMIT_FORM();
			},
			closeDialog(){
				this.$emit('close', 'close');
			},
			//搜索数据
			initFormFun() {
				return [
					{
						type: 'SELECT',
						label: '联系人类型',
						fieldName: 'contactType',
						itemList: this.createDictList('2517'),
						initialValue: '',
						placeholder:'',
					},
					{
						type: 'INPUT',
						label: '姓名',
						fieldName: 'contactName',
						maxlength:100,
						rules:[
							{required: true, message: '请输入姓名', trigger: 'blur' },
							{ min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
						],
						initialValue: '',
						placeholder:'',
					},
					{
						type: 'SELECT',
						label: '性别',
						fieldName: 'contactSex',
						itemList: this.createDictList('1002'),
						initialValue: '',
						placeholder:'',
					},
					{
						type: 'INPUT',
						label: '职务',
						fieldName: 'contactJob',
						maxlength:100,
						rules:[
							{ min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
						],
						initialValue: '',
						placeholder:'',
					},
					{
						type: 'INPUT',
						label: '手机',
						fieldName: 'contactMobile',
						maxlength:100,
						rules:[
							{required: true, message: '请输入', trigger: 'blur' },
							{ min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' },
							{pattern:/^[1][3,4,5,7,8][0-9]{9}$/,message:'请填写正确的手机号格式',trigger: 'blur'}
						],
						initialValue: '',
						placeholder:'',
					},
					{
						type: 'INPUT',
						label: '邮箱',
						fieldName: 'contactEmail',
						maxlength:100,
						rules:[
							{type:'email', message: '请输入正确的邮箱', trigger: 'blur' },
							{ min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
						],
						initialValue: '',
						placeholder:'',
					},
					{
						type: 'DATE',
						label: '出生日期',
						fieldName: 'birthday',
						initialValue: '',
						placeholder:' ',
						change:val => {
							//验证时间不能选择未来
							if(val){
								if(new Date() <= new Date(val)){
									this.initForm.find(x => x.fieldName === 'birthday').initialValue = '';
									this.$notify.warning({title: '提示信息',message:'请选择当前日期之前的时间!'});
								}
							}
						}
					},
					{
						type: 'INPUT',
						label: '家庭住址',
						fieldName: 'homeAddress',
						selfCols:2,
						maxlength:100,
						rules:[
							{ min: 0, max: 100, message: '长度在 0 到 100 个字符', trigger: 'blur' }
						],
						initialValue: '',
						placeholder:'',
					},
					{
						type: 'TEXT_AREA',
						label: '个人喜好',
						fieldName: 'hobby',
						selfCols:3,
						rows: 2,
						maxlength:200,
						rules:[
							{ min: 0, max: 200, message: '长度在 0 到 200 个字符', trigger: 'blur' }
						],
						initialValue: '',
						placeholder:'',
					}
				];
			}
		}
	};
</script>